<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php 
session_start();
include("sql.php");
if (!isset($_SESSION["email"])){echo" no login"; echo "<script language=\"javascript\">location.href=\"prob_quiz.php\";</script>";die();}
if ( isset($_POST['skip'])){include("skip.php");}
if (!isset($_POST['ans'])){echo" no post";echo "<script language=\"javascript\">location.href=\"prob_quiz.php\";</script>"; die(); }
if ($_SESSION['aq']==-1){echo" no aq";echo "<script language=\"javascript\">location.href=\"prob_quiz.php\";</script>";die();}
$email=$_SESSION['email'];
$ans=$_POST['ans'];
$qno=$_SESSION['aq'];
//echo "select rite from ques where qno=$qno;";
$query="select rite from ques where qno=$qno;";
$result=mysql_query($query);
if (!mysql_query($query))
  {
  die('Error: ' . mysql_error());
  } 
$row = mysql_fetch_array($result);
$query2="select score from login where email=\"$email\";";
$result2=mysql_query($query2);
if (!mysql_query($query2))
  {
  die('Error: ' . mysql_error());
  } 
$row2 = mysql_fetch_array($result2);
$score=$row2[0];
//echo "$row[0]";
	if($row[0]==$ans){$score+=5;   echo  "<script language=\"javascript\"> alert(\"correct answer \\n your new score is $score\")</script>";}
	else {
	$query4="select * from ques where qno=$qno";
	$result4=mysql_query($query4);
	if (!mysql_query($query4)){ die('Error: ' . mysql_error()); } 
	$row3 = mysql_fetch_array($result4);
	
	if($row[0]=='A'){$correct=$row3[2];}
	if($row[0]=='B'){$correct=$row3[3];}
	if($row[0]=='C'){$correct=$row3[4];}
	if($row[0]=='D'){$correct=$row3[5];}
	$score-=2;
	echo  "<script language=\"javascript\"> alert(\"incorrect answer \\nyour new score is $score \\ncorrect answer was $correct\")</script>";
}
$qn='q'.$qno;
$updateq="update usertrack set $qn=1 where email=\"$email\"";
$time=time();
$updateu="update login set aq=-1,score=$score,time=\"$time\" where email=\"$email\"";
$_SESSION['aq']=-1;
if (!mysql_query($updateq)){die('Error: ' . mysql_error()); }
if (!mysql_query($updateu)){die('Error: ' . mysql_error()); }
echo "<script language=\"javascript\">location.href=\"prob_quiz.php\";</script>";
?> 
</body>
</html>
